package org.mock.controller;

import com.alibaba.fastjson2.JSONObject;
import lombok.AllArgsConstructor;
import org.mock.service.TravelPortService;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * travelPort mock
 *
 * @author AI
 * @since 2020-06-19
 */
@RestController
@AllArgsConstructor
@RequestMapping("travelPort/mock")
public class TravelPortMockController {

    private TravelPortService travelPortService;

    /**
     * 获取token
     *
     * @return
     * @
     */
    @PostMapping("getToken")
    public JSONObject getToken(@RequestParam Map<String, Object> request) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("accessToken", "travelPortToken");
        return jsonObject;
    }

    /**
     * getHotelAvail
     *
     * @param request
     * @return
     */
    @PostMapping("/11/hotel/search/properties")
    public String getHotelAvail(@RequestBody JSONObject request) {
        return travelPortService.getHotelAvail(request);
    }

    /**
     * getHotelDetail
     * @param request
     * @return
     */
    @PostMapping("/11/hotel/availability/catalogofferingshospitality")
    public String getHotelDetails(@RequestBody JSONObject request) {
        return travelPortService.getHotelDetails(request);
    }

    /**
     * priceCheck
     * @param request
     * @return
     */
    @PostMapping("/11/hotel/rules/offershospitality/buildfromcatalogofferings")
    public String priceCheck(@RequestBody JSONObject request) {
        return travelPortService.priceCheck(request);
    }

    /**
     * 下单
     * @param request
     * @param acceptGuaranteeChangeInd
     * @return
     */
    @PostMapping("/11/hotel/book/reservations/build")
    public String createPnr(@RequestBody JSONObject request, @RequestParam String acceptGuaranteeChangeInd) {
        if (acceptGuaranteeChangeInd.equals("true")) {
            return travelPortService.createPnr(request);
        } else {
            return "error";
        }
    }
}
